/*
 * Created on Sept 15, 2004
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package moca.core.proxy.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * @author hana
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class MocaProperties extends Properties {
  
  private static final Logger logger = Logger.getLogger(MocaProperties.class);
  
  private static final String DEFAULT_CIS_SERVER_HOST = "localhost";
  
  private static final int DEFAULT_CIS_SERVER_PORT = 55001;  
  
  private static final int DEFAULT_CIS_PUBLISHER_PORT = 55000;

  
  //@TODO: Estou passando como parametro o diretorio onde procurar o arquivo de properties
  //Ver se essa eh a melhor maneira
  public MocaProperties() {
    super();
    try { 
      //this.load(new FileInputStream("moca.properties"));
    	InputStream is = this.getClass().getResourceAsStream("/moca.properties");
    	this.load(is);

    }
    catch (FileNotFoundException e) {
      logger.error("Properties file not found.", e);
    }
    catch (IOException e) {
      logger.error("Error while acessing properties file.", e);
    }
  }  
  
  public String getCisServerHost() {
    String cisServerHost = getProperty("cis.server.host");
    cisServerHost = (cisServerHost != null) ? cisServerHost : DEFAULT_CIS_SERVER_HOST;
    return cisServerHost;
  }

  public int getCisServerPort() {
    String temp = getProperty("cis.server.port");
    int cisServerPort = (temp != null) ? Integer.parseInt(temp) : DEFAULT_CIS_SERVER_PORT;
    return cisServerPort;
  }  
  
  public int getCisPublisherPort() {
    String temp = getProperty("cis.publisher.port");
    int cisPublisherPort = (temp != null) ? Integer.parseInt(temp) : DEFAULT_CIS_PUBLISHER_PORT;
    return cisPublisherPort;
  }  
  
  public String getDsServerHost() {
   return getProperty("ds.host");   
 }
 
}

